<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">


            <h:form>
                <p:panel toggleable="true" id="salesForecastCreate" header="Create a Long Term SalesForcast ">
                    <h:panelGroup id="messagePane" layout="block">
                        <h:messages globalOnly="true" errorStyle="color: red" infoStyle="color: green" layout="table"/>
                    </h:panelGroup>


                    <h:panelGrid columns="3">
                        <h:outputLabel value="ForecastingYear"  />
                        
                          <h:selectOneMenu required ="true" id="year" value="#{expectedYearOnYearGrowthEntityController.selected.yearOfSales}" title="#{bundle.CreateSalesLeadEntityTitle_title}" >
                            <f:selectItems value="#{expectedYearOnYearGrowthEntityController.year}"/>
                        </h:selectOneMenu>
     
                        <h:message styleClass="errorMsg" for= "year"/>

                        <h:outputLabel value="ForecastingPeriod" for="periodType" />
                        <h:selectOneMenu id="periodType" value="#{expectedYearOnYearGrowthEntityController.selected.forecastPeriodType}" title="periodType" >
                            <f:selectItems value="#{expectedYearOnYearGrowthEntityController.forecastPeriodType}"/>

                        </h:selectOneMenu>                    
                        <h:message styleClass="errorMsg" for= "periodType"/>

                        <h:outputLabel value="GrowthRate (%)" for="growthRate" />
                        <p:inputText  required ="true" requiredMessage="growthRate is missing" 
                                      id="growthRate" value="#{expectedYearOnYearGrowthEntityController.selected.growthRate}" /> 
                        <h:message styleClass="errorMsg" for= "growthRate"/>


                    </h:panelGrid>
                </p:panel>
               


                <p:commandButton id="creation" value="Generate" action="#{expectedYearOnYearGrowthEntityController.create}" rendered="#{loginBacking.createNewSalesForecast}" update ="panel,books" >

                </p:commandButton>
 
                <p:commandButton value="Market Trend" update="display" oncomplete="marktetTrendDialog.show()"/>
 <p:separator/>
            <p:panel  header="History Sales Forecasts" id="SalesForecast" toggleable="true">
           
               <p:outputPanel id="books"> 
                        <p:dataTable value="#{expectedYearOnYearGrowthEntityController.items}" 
                                     var="item" style="text-align: center"
                                     paginator="true" rows="10"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="5,10,15">
                            <p:column filterBy="#{item.yearOfSales}">
                                <f:facet name="header">
                                    <h:outputText value="Year"/>
                                </f:facet>
                                <h:outputText value="#{item.yearOfSales}"/>
                            </p:column>      
                            
                            <p:column filterBy="#{item.forecastPeriodType}">
                                <f:facet name="header">
                                    <h:outputText value="Forecast Period"/>
                                </f:facet>
                                <h:outputText value="#{item.forecastPeriodType}"/>
                            </p:column>  
                            
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="&nbsp;"/>
                                </f:facet>
                                <p:menuButton value="Options" >
                                     <p:menuitem value=" View" ajax="false" icon="ui-icon ui-icon-search" 
                                                action="#{expectedYearOnYearGrowthEntityController.prepareView}" rendered="#{item.archived==false and loginBacking.viewAllSalesForecast}"/>  
                               
                                     <p:menuitem value=" Delete" ajax="false" rendered="#{item.archived==false and loginBacking.deleteSalesForecast}" icon="ui-icon ui-icon-close"
                                                action="#{expectedYearOnYearGrowthEntityController.destroy}"/> 
                                </p:menuButton>
                                
                            </p:column>
                           
                        </p:dataTable>   
                   </p:outputPanel >
                 
                
       
            </p:panel>
 

                  
                  <h:commandLink value="Generate SalesForecast Production report" target="blank_" action="#{jasper.generateSalesForecastManagementReport}"/>
                  <br/>
                  <h:commandLink  title="Download">  
                  <p:graphicImage value="/images/download.gif" />  
                  <p:fileDownload value="#{download.file1}"/>  
                  </h:commandLink>
                <br/>
 
            

            
                <p:dialog header="Market Trend" widgetVar="marktetTrendDialog" resizable="false"  
                          width="520" showEffect="explode" hideEffect="explode">  

                    <p:lineChart model="#{expectedYearOnYearGrowthEntityController.marketTrends}" minY="24000" titleX="Year" titleY="Sales"  >  
<!--                    <p:chartSeries label="Market FruitsBar Sales" value="#{trend. fruitsBarQuantity}" />  
                    <p:chartSeries label="Market NutsBar Sales" value="#{trend. nutsBarQuantity}" />  -->
                    </p:lineChart>  

                </p:dialog>

            </h:form>
        </ui:define>
    </ui:composition>

</html>

